<?php
if ( !defined('IN_SEC') ){exit();}
?>
<?php include template("admin_header");?>
                <div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

<?php include template("admin_breadcrumb");?>
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1><?php echo $_G['admincp']['actname']; ?><small><i class="icon-double-angle-right"></i><?php echo $_G['admincp']['optname']; ?></small></h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="row-fluid">
									<div class="span12">
										<div class="widget-box">
											<div class="widget-header widget-header-blue widget-header-flat">
												<h4 class="lighter">新职位</h4>
											</div>

											<div class="widget-body">
												<div class="widget-main">
													<div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
														<ul class="wizard-steps">
															<li data-target="#step1" class="active">
																<span class="step">1</span>
																<span class="title">填写信息</span>
															</li>

															<li data-target="#step2">
																<span class="step">2</span>
																<span class="title">授权</span>
															</li>

															<li data-target="#step3">
																<span class="step">3</span>
																<span class="title">验证权限</span>
															</li>
														</ul>
													</div>

													<hr />
													<div class="step-content row-fluid position-relative" id="step-container">
													<form class="form-horizontal" action="?action=account&operation=editgroup&id=<?php echo $department['id']; ?>" id="validation-form" method="post">
														<div class="step-pane active" id="step1">
                                                            <input name="id" value="<?php echo $group['id']; ?>" type="hidden" />
																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="name">职位名称:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="name" name="name" value="<?php echo $group['name']; ?>" maxlength="16" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">所属部门</label>

																	<div class="col-xs-12 col-sm-9">
																		<select id="departmentid" name="departmentid" class="select2" data-placeholder="选择..."><?php echo option($departments, $group['departmentid'], '通用'); ?></select>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">直属上级</label>

																	<div class="col-xs-12 col-sm-9">
																		<select id="parentid" name="parentid" class="select2" data-placeholder="选择..."><?php echo option($groups, $group['parentid'], '无上级'); ?></select>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">等级</label>

																	<div class="col-xs-12 col-sm-9">
																		<input type="text" name="rank" value="<?php echo intval($group['rank']); ?>" class="input-mini" id="spinner3" />
																	</div>
																</div>
														</div>

														<div class="step-pane" id="step2">
				<table id="sample-table-1" class="table table-striped table-bordered table-hover">
					<tbody>
<?php if(is_array($actions)){foreach($actions AS $k=>$v) { ?>
						<tr>
							<td width="20"><input type="checkbox" name="act[<?php echo $v['name']; ?>]" value="1" class="ace checkall mixed-<?php echo $v['mixed']; ?>" sups="<?php echo $v['super']; ?>" action="<?php echo $v['name']; ?>" <?php if($v['mixed'] || count($v['submenu']) == count($gact[$v['name']])){?>checked="checked"<?php }?>><span class="lbl"></span></td>
							<td width="80"><b><?php echo $v['title']; ?></b></td>
							<td>
<?php if($v['submenu']){?>
<?php if(is_array($v['submenu'])){foreach($v['submenu'] AS $sub) { ?>
								<input type="checkbox" name="opt[<?php echo $v['name']; ?>][<?php echo $sub['name']; ?>]" class="ace check-<?php echo $v['name']; ?> super-<?php echo $sub['super'] ? $sub['super'] : $v['super']; ?> mixed-<?php echo $sub['mixed']; ?>" value="<?php echo $sub['id']; ?>" <?php if($sub['mixed'] || $gact[$v['name']][$sub['id']]){?>checked="checked"<?php }?> <?php if($admincp->allow != 'all' && !$admincp->allow[$v['id']][$sub['id']]){?>disabled="disabled"<?php }?>><span class="lbl"></span><?php echo $sub['title']; ?>
<?php }}?>
<?php }?>
							</td>
				        </tr>
<?php }}?>
					</tbody>
				</table>

														</div>

														<div class="step-pane" id="step3">
																<div class="alert alert-info">
																	<button type="button" class="close" data-dismiss="alert">
																		<i class="icon-remove"></i>
																	</button>
																	<strong>注意!</strong> 您需要输入您的密码来进行授权操作
																</div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">密码</label>

																	<div class="col-xs-12 col-sm-9">
																			<input type="password" name="confirm_password" value="" class="col-xs-12 col-sm-5" />
																	</div>
																</div>
														</div>
													</form>
													</div>

													<hr />
													<div class="row-fluid wizard-actions">
														<button class="btn btn-prev">
															<i class="icon-arrow-left"></i>上一步
														</button>

														<button class="btn btn-success btn-next" data-last="完成">下一步
															<i class="icon-arrow-right icon-on-right"></i>
														</button>
													</div>
												</div><!-- /widget-main -->
											</div><!-- /widget-body -->
										</div>
									</div>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
<?php include template("admin_footer");?>
		<!-- page specific plugin styles -->

		<link rel="stylesheet" href="/static/ace/assets/css/select2.css" />
		<!-- page specific plugin scripts -->

		<script src="/static/ace/assets/js/fuelux/fuelux.spinner.min.js"></script>
		<script src="/static/ace/assets/js/fuelux/fuelux.wizard.min.js"></script>
		<script src="/static/ace/assets/js/jquery.validate.min.js"></script>
		<script src="/static/ace/assets/js/additional-methods.min.js"></script>
		<script src="/static/ace/assets/js/bootbox.min.js"></script>
		<script src="/static/ace/assets/js/jquery.maskedinput.min.js"></script>
		<script src="/static/ace/assets/js/select2.min.js"></script>
		<script type="text/javascript">
			D.Main = {
				init : function(){
					var maxlv = "<?php echo $maxlv; ?>";
					$('.mixed-1').on('click', function(){
						var obj = $(this);
						bootbox.alert('该选项无法取消');
						return false;
					});
					$('.checkall').on('click', function(){
						var obj = $(this);
						var act = obj.attr('action');
						var sups = obj.attr('sups');
						var checked = obj.is(':checked');
						if ( obj.hasClass('mixed-1') ){
						}else if ( sups == 1 && checked ){
							bootbox.confirm('该权限为高级权限，您是否确认操作？', function(result){
								if( result ){
									$('.check-' + act).prop('checked', checked);
								}
							});
						}else{
							$('.check-' + act).prop('checked', checked);
						}
					});
					$('.rel-checkall').bind('click', function(){
						$("input").prop('checked', true);
					});
					$('.super-1').on('click', function(){
						var obj = $(this);
						var checked = obj.is(':checked');
						if ( checked ){
							bootbox.confirm('该权限为高级权限，您是否确认操作？', function(result){
								if( result ){
									obj.prop('checked', checked);
								}
							});
							return false;
						}
					});

					$('#spinner3').ace_spinner({value : $('#spinner3').val(), min:0,max:98,step:1, on_sides: true, icon_up:'icon-plus smaller-75', icon_down:'icon-minus smaller-75', btn_up_class:'btn-success' , btn_down_class:'btn-danger'});
					$('#departmentid').change(function(){
						var departmentid = $(this).val();
						var html = '<option>无上级</option>';
						$('#parentid').html(html + '<option disabled="disabled">数据加载中...</optgroup>').select2({allowClear:true});
						D.ajax.get('?action=account&operation=edit&departmentid='+departmentid+'&act=get_groups', function(json){
							if( json.data ){
								$.each(json.data, function(i, n){
									html += '<option value="'+n.id+'">'+n.name+'</option>';
								});
							}
							$('#parentid').html(html).select2({allowClear:true});
						});
					});
				}
			}

			jQuery(function($) {
				$('[data-rel=tooltip]').tooltip();
				$(".select2").css('width','200px').select2({allowClear:true}).on('change', function(){
					$(this).closest('form').validate().element($(this));
				}); 
			
				var $validation = true;
				$('#fuelux-wizard').ace_wizard().on('change' , function(e, info){
					if(info.step == 1 && $validation) {
						if(!$('#validation-form').valid()) return false;
					}
				}).on('finished', function(e) {
					var data = $('#validation-form').serialize();
					var loading = bootbox.dialog({
						message: '<div class="tree-loading" style="text-align: center;"><i class="icon-refresh icon-spin blue"></i></div>' 
					});
					D.ajax.postdata($('#validation-form').attr('action'), data, function(json){
						bootbox.hideAll();
						var buttons = json.error ? {
							danger : {
								label : "错误",
								className : "btn-sm btn-primary"
							}
						} : {
							success : {
								label : "OK",
								className : "btn-sm btn-primary",
								callback : function(){
									window.location.reload();
								}
							}
						};
						bootbox.dialog({
							message: json.data, 
							buttons: buttons
						});
					});
				}).on('stepclick', function(e){
					//return false;//prevent clicking on steps
				});

				//documentation : http://docs.jquery.com/Plugins/Validation/validate
			
				$.mask.definitions['~']='[+-]';
				$('#phone').mask('99999999999');
			
				jQuery.validator.addMethod("phone", function (value, element) {
					return this.optional(element) || /^1[3458][\d]{9}$/.test(value);
				}, "请输入一个有效的手机号码.");
			
				$('#validation-form').validate({
					errorElement: 'div',
					errorClass: 'help-block',
					focusInvalid: false,
					rules: {
						email: {
							required: true
						},
						password: {
							required: true,
							minlength: 5
						},
						password2: {
							required: true,
							minlength: 5,
							equalTo: "#password"
						},
						username : {
							required : true
						},
						name: {
							required: true
						},
						phone: {
							required: true,
							phone: 'required'
						},
						url: {
							required: true,
							url: true
						},
						comment: {
							required: true
						},
						state: {
							required: true
						},
						platform: {
							required: true
						},
						subscription: {
							required: true
						},
						gender: 'required',
						agree: 'required'
					},
			
					messages: {
						username : {
							required : '请输入部门名称'
						},
						name: {
							required: "请输入部门名称"
						},
						password: {
							required: "请输入密码.",
							minlength: "请输入密码."
						},
						subscription: "Please choose at least one option",
						gender: "请选择性别",
						agree: "Please accept our policy"
					},
			
					invalidHandler: function (event, validator) { //display error alert on form submit   
						$('.alert-danger', $('.login-form')).show();
					},
			
					highlight: function (e) {
						$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
					},
			
					success: function (e) {
						$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
						$(e).remove();
					},
			
					errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else error.insertAfter(element.parent());
					},
			
					submitHandler: function (form) {
					},
					invalidHandler: function (form) {
					}
				});

				$('#modal-wizard .modal-header').ace_wizard();
				$('#modal-wizard .wizard-actions .btn[data-dismiss=modal]').removeAttr('disabled');
			});
		</script>
</body>
</html>
